﻿#include<iostream>
using namespace std;
int main() {
	unique_ptr<int> intPtr1{ new int{5} };
	cout << intPtr1 << " " << *intPtr1 << endl;//0000018085BC9770 5

	int* a2 = new int[5];
	unique_ptr<int[]> intPtr2{ new int[5] {5,4,3,2,1} };
	cout << intPtr2 << " " << intPtr2[1] << endl;//00000270ED220820 4

	//intPtr2 = intPtr1;//报错，无法指针指向指针
	//unique_ptr<int[]> intPtrA{ intPtr1 };//报错，无法指针指向指针

	//C++14以后声明
	unique_ptr<int[]> intPtrA{ make_unique<int[]>(5) };//有5个数组元素
	unique_ptr<int> intPtrB{ make_unique<int>(5) };//指针声明初始化为5

	intPtrA.reset();//（1）指针地址清零（2）内存空间释放

	int* a1{ intPtrB.get() };//得到intPtrB指向的内存地址

	cout << a1 << " " << *a1 << endl;//0000024329A45220 5
	cout << intPtrB << " " << *intPtrB << endl;//0000024329A45220 5

	intPtrB.release();//将指针指向空，但是不释放原来内存空间的值

	//cout << intPtrB << " " << *intPtrB << endl;

	unique_ptr<int[]> intPtrC{ make_unique<int[]>(5) };
	unique_ptr<int[]> intPtrD{  };

	cout << intPtrC << " " << intPtrD << endl;

	intPtrD = move(intPtrC);//让intPtrD指向intPtrC指向的内存地址，然后将intPtrC指向空

	cout << intPtrC << " " << intPtrD << endl;
}